# pythagorean triple generator
#   a = k.(m^2 - n^2)
#   b = 2.k.m.n
#   c = k.(m^2 + n^2)
# with:
#   m > n
#   m and n coprime
#   m - n odd
#
# Perimeter of the trianlge:
#   Per = a + b + c
#   Per = k.(m^2 - n^2) + 2.k.m.n + k.(m^2 + n^2)
#   Per = k.(m^2 - n^2 + m^2 + n^2) + 2.k.m.n
#   Per = 2.k.m^2 + 2.k.m.n
#   Per = 2.k.m.(m + n)
#   Per/2 = k.m.(m + n)
#
#   Per/2 = 2.2.5.5.5
#   Per/2 = 1.500 = 2.250 = 4.125 = 5.100 = 10.50 = 25.20
#
# m and (m + n)  must be a divisor of Per/2
#
# Product a.b.c
#   Pro = a.b.c
#   Pro = k.(m^2 - n^2).2.k.m.n.k.(m^2 + n^2)
#   Pro = 2.k^3.m.n.(m^4 - n^4)

import lib.integer

def divisor(n):
    result, div = [], 1
    while div * div < n:
        if n % div == 0:
            result.append(div)
            result.append(n // div)
        div += 1
    return result

def Solve():
    # divisor list of 500
    div = divisor(500)

    # for all divisor m
    for m in div:
        # check m + n divisor
        for mpn in div:
            # Check m and n condition
            n = mpn - m
            if n * mpn > 500:              continue
            if n <= 0 or n > m:            continue
            if m - n % 2 == 0:             continue
            if lib.integer.Gcd(m, n) != 1: continue

            # We found valid m and n for the pythagorean triple
            k = 500 / (m * mpn)

            return 2 * k**3 * m * n * (m**4 - n**4)


